package com.server.process.controller;

import com.server.common.entity.Result;
import com.server.common.entity.ResultCode;
import com.server.domain.process.WorkFlow;
import com.server.process.service.WorkFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
@RequestMapping(value = "/workflow")
public class WorkFlowController {
    @Autowired
    private WorkFlowService workFlowService;

    // 新建工作流
    @RequestMapping(value = "/new", method = RequestMethod.POST)
    public Result save(@RequestBody WorkFlow workFlow){
        // 业务操作
        workFlowService.add(workFlow);
        // 返回Result
        return new Result(ResultCode.SUCCESS);
    }
    //根据companyId查询工作流
    @RequestMapping(value = "/mylist/{companyId}", method = RequestMethod.GET)
    public Result findByCompanyId(@PathVariable(value = "companyId") String companyId) {
        return new Result(ResultCode.SUCCESS, workFlowService.findByCompanyId(companyId));
    }
    //根据工作流id查询工作流
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Result findById(@PathVariable(value = "id") String id){

        return new Result(ResultCode.SUCCESS, workFlowService.findById(id));
    }
}
